package com.info.zhiduoduo.repository.util;

import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;

/**
 * 脱敏工具类
 */
public class DesensitizeUtil {

    /**
     * 名字脱敏
     * @param fullName
     * @return
     */
    public static String desensitizedName(String fullName){
        if (!Strings.isNullOrEmpty(fullName)) {
            String name = StringUtils.left(fullName, 1);
            return StringUtils.rightPad(name, StringUtils.length(fullName), "*");
        }
        return fullName;
    }

    /**
     * 手机号脱敏
     * @param phoneNumber
     * @return
     */
    public static String desensitizedPhoneNumber(String phoneNumber){
        if(StringUtils.isNotEmpty(phoneNumber)){
            phoneNumber = phoneNumber.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2");
        }
        return phoneNumber;
    }

}
